package com.now.printer.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import com.now.printer.R;
import com.now.printer.base.BaseActivity2;
import com.now.printer.idcardcamera.camera.IDCardCamera;

@Deprecated
public class IDCardActivity extends BaseActivity2 implements View.OnClickListener {

    private Button btn_front, btn_back;
    private ImageView iv_id_card_front, iv_id_card_back;

    @Override
    public int getLayoutId() {
        return R.layout.activity_idcard;
    }

    @Override
    public void doBusiness(Context mContext) {

        btn_front = findViewById(R.id.btn_front);
        btn_back = findViewById(R.id.btn_back);
        btn_front.setOnClickListener(this);
        btn_back.setOnClickListener(this);

        iv_id_card_front = findViewById(R.id.iv_id_card_front);
        iv_id_card_back = findViewById(R.id.iv_id_card_back);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_front:

                IDCardCamera.create(this).openCamera(IDCardCamera.TYPE_IDCARD_FRONT);
                break;
            case R.id.btn_back:
                IDCardCamera.create(this).openCamera(IDCardCamera.TYPE_IDCARD_BACK);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == IDCardCamera.RESULT_CODE) {
            //获取图片路径，显示图片
            final String path = IDCardCamera.getImagePath(data);
            if (!TextUtils.isEmpty(path)) {
                if (requestCode == IDCardCamera.TYPE_IDCARD_FRONT) { //身份证正面
                    iv_id_card_front.setImageBitmap(BitmapFactory.decodeFile(path));
                } else if (requestCode == IDCardCamera.TYPE_IDCARD_BACK) {  //身份证反面
                    iv_id_card_back.setImageBitmap(BitmapFactory.decodeFile(path));
                }
            }
        }
    }
}